package com.xd.springboot.controller;

import com.xd.springboot.entity.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/mvc")
public class MvcController {

    private  static Logger logger= LoggerFactory.getLogger(MvcController.class);

    @RequestMapping("/user")
    public User getUser()
    {
        User user=new User();
        user.setUsername("老王");
        user.setPassword("1111");
        return user;
    };

    @GetMapping("/user/{username}/{password}")
    public  String testPathVariable(@PathVariable(value = "username") String name,@PathVariable String password)
    {
        logger.info("获取到的Path参数为：{}",name);
        logger.info("获取到的Path参数为：{}",password);
        return name + password;
    }

    @GetMapping("/usertest")
    public  String testRequestParam(@RequestParam(value = "username") String name, @RequestParam String password)
    {
        logger.info("获取到的RequestParam参数为：{}",name);
        logger.info("获取到的RequestParam参数为：{}",password);
        return name + password;
    }

    @PostMapping("/form2")
    public String testForm(User user)
    {
        logger.info("获取到的username:" + user.getUsername());
        return "success";
    }
}
